package leaveSystem.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public abstract class DAOFactory {
	
	private static final String dbUrl = "jdbc:mysql://localhost:3306/leaveapp";
	private static final String dbUserName = "root";
	private static final String dbPassword = "password";
	private static Connection conn = null;
	
	// to load DAOFactory
	public static DAOFactory loadInstance() {
		return new leaveSystem.dao.mysql.DAOFactoryImpl();
	}

	public abstract EmployeeDAO getEmployeeDAO();
	public abstract EmployeeWorkscheduleDAO getEmployeeWorkscheduleDAO();
	public abstract LeaveDAO getLeaveDAO();
	public abstract LeaveTypeDAO getLeaveTypeDAO();
	public abstract PublicHolidaysDAO getPublicHolidaysDAO();
	public abstract RoleDAO getRoleDAO();
	public abstract Compensation_TrackingDao getCompensation_TrackingDao();
	
	//get connection with database
	public static Connection getDatabaseConnection(){
		try {
			Class.forName("com.mysql.jdbc.Driver");
			conn = (Connection) DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
		} catch (Exception e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		return conn;
	}
	public static void closeDatabaseConnection(){
		try {
			conn.rollback();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
